<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html>
<head>
<jsp:include page="../inc_min.jsp"></jsp:include>
<title>报表中心-业务报表</title>
<link rel="stylesheet" href="${ctx}/css/page.css"/>
<link rel="stylesheet" href="${ctx}/css/npOrderQuery.css"/>	
<script type="text/javascript">
	$(function(){
		
		$(".listArg").click(function(){
			$(this).siblings().removeClass("order");
			$(this).addClass("order");
			changeBack($(".listArg"),$(this));
		});
		$(".listArg2").click(function(){
			$(this).siblings().removeClass("checked");
			$(this).addClass("checked");
			changeBack($(".listArg2"),$(this));
		});
		//封装函数  实现背景颜色及字体颜色切换
		function changeBack(arg,$this){
			arg.css({
				"background": "#f1f1f1",
				"color": "black"
			});
			$this.css({
				"background": "#28aaf0",
				"color": "#FFFFFF"
			});
		};
		//点击查询 重新加载列表
		$("#query").click(function(){
            pageNum = 1;
            getData(-1,-1);
		});
        getData(-1,-1);
	});
    var pageNum = 1;
    function getData(orderStatus,financeStatus){
        //获取参数
        var toStartAirportCode=$("#_startCity").val();//出发城市
        var toEndAirportCode=$("#_endCity").val(); //到达城市
        var toStartDate=$("#startDate").val();//开始日期
        var toEndDate=$("#endDate").val();//结束日期
        var buyerName=$("#buyerName").val();//采购商
        var sellerName=$("#sellerName").val();//供应商
        if(typeof(toStartAirportCode) == 'undefined'){
            toStartAirportCode = "";
        }
        if(typeof(toEndAirportCode) == 'undefined'){
            toEndAirportCode = "";
        }
        var param = {
            "orderStatus":orderStatus,
            "financeStatus":financeStatus,
            "toStartAirportCode":toStartAirportCode,
            "toEndAirportCode":toEndAirportCode,
            "toStartDate":toStartDate,
            "toEndDate":toEndDate,
            "buyerName":buyerName,
            "sellerName":sellerName,
            "page":pageNum,
            "rows":20
        }
        $.get('${ctx}/search/getPlatformList?temp='+Math.random(),param,function(data){
            $('table tbody').empty();

            for(var i=0;i<data.rows.length;i++){
                var obj = data.rows[i];
                var intervalDay=CommonConverter.toEmptyStr(obj.list[0].intervalDay);
                if(intervalDay != 0){
                    intervalDay ="+"+intervalDay;
                };
                var str = "";
                str+="<tr class='reBorder' height='37'>"
                str+="	<td  colspan='10' height='37'>"
                str+="		<span class='orderNumberSpan'>平台订单号："+obj.orderNumber+"</span>"
                str+="		<span class='orderNumberSpan'>采购商订单号："+obj.pssOrderNumber+"</span>"
                str+="		<span class='statusText blue'>"+CommonConverter.toOrderBizStatusStr(obj.orderStatus)+"/<span class='orange'>"+CommonConverter.toOrderPayStatusStr(obj.financeStatus)+"</span></span>"
                str+="	</td>"
                str+="</tr>"
                str+="<tr height='90'>"
                str+="	<td align='center'>"
                str+="		往：<span style='color:black;'>"+obj.list[0].airlineNumber+"</span><br/>"
                str+= (obj.list.length==2) ?  "返：<span style='color:black;'>"+obj.list[1].airlineNumber+"</span>" :  "";
                str+="	</td>"
                str+="	<td align='right'>"
                str+="		<span>"+CommonConverter.formatFlightTime((obj.list)[0].deptTime)+"</span><br/>"
                str+="		<span style='color:#444e50'>"+obj.list[0].deptCity+"</span><span style='color:#444e50'>("+obj.list[0].deptCode+")</span><span style='color:#e2615c'>"+obj.list[0].deptTerminal+"</span><br/>"
                str+= (obj.list.length==2) ?  "<span>"+CommonConverter.formatFlightTime((obj.list)[1].arrTime)+"</span><br/>" :  "";
                str+="	</td>"
                str+="	<td align='center'>"
                str+="		<span style='color:#23b9dc'>"+obj.list[0].deptDate+"</span><br/>"
                str+= (obj.list.length==2) ?  "<img src='${ctx}/image/flightQuery/round.gif'><br/>" :  "<img src='${ctx}/image/flightQuery/dancheng.png'><br/>";
                str+= (obj.list.length==2) ?  "<span style='color:#23b9dc'>"+obj.list[1].deptDate+"</span><br/>" :  "";
                str+="	</td>"
                str+="	<td>"
                str+="		<span>"+CommonConverter.formatFlightTime((obj.list)[0].arrTime)+"</span><span style='color:#e2615c;'>"+intervalDay+"</span><br/>"
                str+="		<span style='color:#444e50'>"+obj.list[0].arrCity+"</span><span style='color:#444e50'>("+obj.list[0].arrCode+")</span><span style='color:#e2615c'>"+obj.list[0].arrTerminal+"</span><br/>"
                str+= (obj.list.length==2) ?  "<span>"+CommonConverter.formatFlightTime((obj.list)[1].deptTime)+"</span><br/>" :  "";
                str+="	</td>"
                str+="	<td>"
                str+="		卖家：<span class='red'>"+obj.sellerName+"</span><br/>"
                str+="		买家：<span class='blue'>"+obj.buyerName+"</span><br/>"
                str+="		姓名：<span class='black'>"+CommonConverter.toEmptyString(obj.createuserName)+"</span><br/>"
                str+="		电话：<span class='black'>"+CommonConverter.toEmptyString(obj.mobile)+"</span>"
                str+="	</td>"
                str+="	<td align='center'><span class='red'>"+CommonConverter.toEmptyString(obj.actualTicketedCount)+"/</span><span class='blue'>"+obj.purchQuantity+"</span></td>"
                str+="	<td align='center' class='black'>"+obj.sellingPrice+"</td>"
                str+="	<td align='center'><span class='blue'>"+(obj.purchQuantity)*(obj.sellingPrice)+"/</span><span class='red'>"+obj.sum+"</span></td>"
                str+="	<td align='center' class='black'>"+obj.charges+"</td>"
                str+="	<td align='center'><span class='blue'>"+CommonConverter.formatMoney(parseFloat(obj.sum)-parseFloat(obj.charges))+"/</span><span class='red'>"+CommonConverter.formatMoney(parseFloat(obj.sum)-parseFloat(obj.charges))+"</span></td>"
                str+="</tr>"
                $('#tb').append(str);
            }

            //显示分页
            layui.use(['laypage', 'layer'], function(){
                var laypage = layui.laypage;
                laypage({
                    cont: 'pager'
                    ,pages:  Math.ceil(data.total/20) //得到总页数 //总页数
                    ,groups: 5 //连续显示分页数
                    ,skin: '#1E9FFF'
                    ,curr : pageNum
                    ,jump: function(obj,first){
                        if(!first){
                            pageNum = obj.curr;
                            getData(orderStatus,financeStatus);
                        }
                    }
                });
            });
        })
    }

	//导出表格
	function exportExcel(){
		var orderStatus=$("#orderStatus").val(); //订单状态
		var toStartAirportCode=$("#_startCity").val();//出发城市
		var toEndAirportCode=$("#_endCity").val(); //到达城市
		var toStartDate=$("#startDate").val();//开始日期
		var toEndDate=$("#endDate").val();//结束日期
		var buyerName=$("#buyerName").val();//采购商
		var sellerName=$("#sellerName").val();//供应商
		//获取当前被选中的财务状态
		var financeStatus=$(".conditionFince").find(".checked").find("span").attr('id');
		//获取当前被选中的业务状态
		var orderStatus=$(".order").attr('name');
		if(typeof(toStartAirportCode) == 'undefined'){
			toStartAirportCode = "";
		}
		if(typeof(toEndAirportCode) == 'undefined'){
			toEndAirportCode = "";
		}
		var url = "${ctx}/excel/exportSheets3?orderStatus="+orderStatus
		+"&toStartAirportCode="+toStartAirportCode
		+"&toEndAirportCode="+toEndAirportCode
		+"&toStartDate="+toStartDate
		+"&toEndDate="+toEndDate
		+"&buyerName="+buyerName
		+"&sellerName="+sellerName
		+"&financeStatus="+financeStatus
		+"&temp="+Math.random();
		window.location.href = url;
	};
</script>
</head>
<body>
<jsp:include page="../head.jsp"/>
	<div class="content">
		<div class="list">
			<ul class="listBox">
					<li>
					          统计日期 ：<input type="text" id="startDate" style="height: 18px" class="textbox" value="${requestScope.deptDate}" onFocus="new WdatePicker({dateFmt:'yyyy-MM-dd'/*,minDate:'%y-%M-\#{%d+2}',maxDate:'#F{$dp.$D(\'endDate\')}'*/})"/>
						<img class="city" src="${ctx}/image/date.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						至<input type="text" id="endDate" class="textbox" style="height: 18px" value="${requestScope.endDate}" onFocus="new WdatePicker({dateFmt:'yyyy-MM-dd'/*,minDate:'#F{$dp.$D(\'startDate\')}'*/})">
						<img class="city" src="${ctx}/image/date.gif">
					</li>
					<li>
						采购商：<input  id="buyerName" name="charterType"  style="width: 120px;height: 18px"/>
					</li>
					<li>
						供应商：<input  id="sellerName" name="charterType"  style="width: 120px;height: 18px"/>
					</li>
					<li>出发城市：
						<input type="text" value="" size="15" id="homecity_name" name="homecity_name" style="width:130px;height: 18px" mod="address|notice" mod_address_source="hotel" mod_address_suggest="" mod_address_reference="_startCity" mod_notice_tip="中文/拼音" />
						<input id="_startCity" name="_startCity" type="hidden" value="" />
					</li>
					<li>到达城市：
						<input type="text" value="" size="15" id="getcity_name" name="getcity_name" style="width:130px;height: 18px" mod="address|notice" mod_address_source="hotel"  mod_address_reference="_endCity" mod_notice_tip="中文/拼音" />
						<input id="_endCity" name="_endCity" type="hidden" value="" />
					</li>
					<li><button class='query right' id="query">查询</button></li>
					<!-- <li><button class='query' onclick="exportExcel()" >导出</button></li> -->
				</ul>
			</div>
			<ul class="conditionList">
				<li>业务状态：</li>
				<li class="listArg allStatus order" name="-1" onclick="getData(-1,-1)"><span>全部</span></li>
				<li class="listArg" onclick="getData(0,-1)" name="0"><span>待支付</span></li>
				<li class="listArg" onclick="getData(2,-1)" name="2"><span>待出票</span></li>
				<li class="listArg" onclick="getData(4,-1)" name="4"><span>出票完成</span></li>
				<li class="listArg" onclick="getData(5,-1)" name="5"><span>已取消</span></li>
			</ul>
			<ul class="conditionList conditionFince">
				<li>财务状态：</li>
				<li class="listArg2 allStatus checked" onclick="getData(-1,-1)"><span id="-1">全部</span></li>
				<li class="listArg2" onclick="getData(-1,1)"><span id="1">收款待审核</span></li>
				<li class="listArg2" onclick="getData(-1,2)"><span id="2">已收款</span></li>
				<li class="listArg2" onclick="getData(-1,3)"><span id="3">待提现</span></li>
				<li class="listArg2" onclick="getData(-1,4)"><span id="4">提现待审核</span></li>
				<li class="listArg2" onclick="getData(-1,5)"><span id="5">提现待支付</span></li>
				<li class="listArg2" onclick="getData(-1,6)"><span id="6">已付款</span></li>
				<li class="right">
					<button class='exportExcel' onclick="exportExcel()" >导出</button>
				</li>
			</ul>
			<table class="conTable">
			 	<thead>
			 		<tr height="38" >
						<td width="122" align="center"><img src="${ctx}/image/flightQuery/flightNumber.gif">航班号</td>
						<td width="159" align="right"><img src="${ctx}/image/flightQuery/flightStart.gif">出发/到达</td>
						<td width="162" align="center">&nbsp;&nbsp;&nbsp;</td>
						<td width="161"><img src="${ctx}/image/flightQuery/flightEnd.gif">到达/出发</td>
						<td width="164" >供应商/采购商</td>
						<td width="90" align="center">实际出票/数量</td>
						<td width="102" align="center">单价（CNY）</td>
						<td width="124" align="center">应收/实收（CNY）</td>
						<td width="72" align="center">佣金（CNY）</td>
						<td width="143" align="center">应付/实付（CNY）</td>
					</tr>
			 	</thead>
				<tbody  id="tb">

				</tbody>
			</table>
        <!-- 分页 -->
        <div id="pager" class="divBox"></div>
		</div>
<script type="text/javascript" src="${ctx }/jslib/airport/fixdiv.js"></script>
<script type="text/javascript" src="${ctx }/jslib/airport/address.js"></script>
<jsp:include page="../footer.jsp"/>
</body>
</html>